
<link type='text/css' href="css/admin_style.css" rel='stylesheet' media='screen' />
<script type="text/javascript" src="js/admin_script.js"></script>

<script type="text/javascript">    
    car = function(id, name, player){
        this.id = id;
        this.name = name;
        this.player = player;
    }
    
    var cars = new Array();
    
    <?php $cars = $grs->getCars(null);?>
    <?php for($i=0;$i<count($cars);$i++): ?> 
        cars[<?php echo $i ?>] = new car("<?php echo $cars[$i]->id ?>", "<?php echo $cars[$i]->name ?>", "<?php echo $grs->getPlayerById($cars[$i]->player_id) ?>");
    <?php endfor ?>
    
    function checkPlayer(){
        var found = false;
        var player_name = document.getElementsByName('player_name')[0].value;
        var select = document.getElementById('cars_selection');
        
        for(var i=0;i<cars.length;i++) {
            if(cars[i].player == player_name){
                found = true;
                appendOptionLast(select, cars[i].id, cars[i].name);
            }
        }
         
        if(!found){
            clearSelect(select);
            alert("Este Jugador no tiene coches.");
        }    
    }
</script>
 
<?php opentable($grs->message('AdminToolbarLabel'));?>	
	<div class="admin_toolbar">
		<button onclick="$('#add_game').dialog('open')"><?php echo $grs->message('AddGameButtonLabel') ?></button>
		<button onclick="$('#add_mode').dialog('open')"><?php echo $grs->message('AddModeButtonLabel') ?></button>
		<button onclick="$('#add_track').dialog('open')"><?php echo $grs->message('AddTrackButtonLabel') ?></button>
		<button onclick="$('#add_player').dialog('open')"><?php echo $grs->message('AddPlayerButtonLabel') ?></button>
		<button onclick="$('#add_rec').dialog('open')"><?php echo $grs->message('AddRecButtonLabel') ?></button>
	</div>
	<div class="clear"></div>
<?php closetable(); ?>

<div class="admin_panels">

<!-- --------------------------------- ADD GAME FORM ------------------------------------------------------------------------------ -->
    <div id="add_game" class="dialog_form" title="<?php echo $grs->message('AddGameTitleLabel') ?>">
    	<div class="result"></div>
        <form action="admin_actions.php" id="form_add_game">
			<input type="hidden" value="ADD_GAME" name="action" />
			<table cellpadding="0" cellspacing="0">
				<tr>
					<th></td><label for="game_name">Juego:</label></th>
					<td><input type="text" name="game_name"/></td>
				</tr>
				<tr>
					<th><label for="img_game">Imagen:</label></th>
					<td><input type="text" name="game_img"/></td>
				</tr>
			</table>
        </form>
    </div>
<!-- --------------------------------- ADD MODE FORM ------------------------------------------------------------------------------ -->    
    <div id="add_mode" class="dialog_form" title="<?php echo $grs->message('AddModeTitleLabel') ?>">
        <div class="result"></div>
		<form action="admin_actions.php" id="form_add_mode">
			<input type="hidden" value="ADD_MODE" name="action" />
			<table cellpadding="0" cellspacing="0">
				<tr>
					<th></td><label for="mode_game">Modo:</label></th>
					<td><input type="text" name="mode_name"/></td>
				</tr>
			</table>
        </form>
    </div>
 <!-- --------------------------------- ADD TRACK FORM ------------------------------------------------------------------------------ -->   
    <div id="add_track" class="dialog_form" title="<?php echo $grs->message('AddTrackTitleLabel') ?>">
        <div class="result"></div>
		<form action="admin_actions.php" id="form_add_track">
            <input type="hidden" value="ADD_TRACK" name="action" />
            <table cellpadding="0" cellspacing="0">
				<tr>
					<th></td><label for="track_game">Pista:</label></th>
					<td><input type="text" name="track_name"/></td>
				</tr>
			</table>
        </form>
    </div>
    
<!-- --------------------------------- ADD PLAYER FORM ------------------------------------------------------------------------------ -->
    <div id="add_player" class="dialog_form" title="<?php echo $grs->message('AddPlayerTitleLabel') ?>">
    	<div class="result"></div>
        <form action="admin_actions.php" id="form_add_player">
			<input type="hidden" value="ADD_PLAYER" name="action" />
			<table cellpadding="0" cellspacing="0">
				<tr>
					<th></td><label for="player_name">Jugador:</label></th>
					<td><input type="text" name="player_name"/></td>
				</tr>
				<tr>
					<th><label for="player_email">Correo:</label></th>
					<td><input type="text" name="player_email"/></td>
				</tr>
			</table>
        </form>
    </div>
<!-- --------------------------------- ADD REC FORM ------------------------------------------------------------------------------ -->    
    <div id="add_rec" class="dialog_form" title="<?php echo $grs->message('AddRecTitleLabel') ?>">
        <div class="result"></div>
		<form action="admin_actions.php" id="form_add_rec">
			<input type="hidden" value="ADD_REC" name="action" />

			<table cellpadding="0" cellspacing="0">
				<tr>
					<th></td><label><?php echo $grs->message('AddRecGameFormLabel') ?></label></th>
					<td>
                        <select 
                            <?php foreach($grs->getGames() as $game) :?>
                                <option name='game_id' value='<?php echo $game->id ?>'><?php echo $game->name?></option>
                            <?php endforeach ?>
                        </select>
					</td>
				</tr>
				<tr>
					<th></td><label><?php echo $grs->message('AddRecModeFormLabel') ?></label></th>
					<td>
                        <select name="mode_id"> 
                            <?php foreach($grs->getModes() as $mode) :?>
                                <option value='<?php echo $mode->id ?>'><?php echo $mode->name?></option>
                            <?php endforeach ?>
                        </select>
                    </td>
				</tr>
				<tr>
					<th></td><label><?php echo $grs->message('AddRecTrackFormLabel') ?></label></th>
					<td>
                        <select name="track_id"> 
                            <?php foreach($grs->getTracks() as $track) :?>
                                <option name='track_id' value='<?php echo $track->id ?>'><?php echo $track->name?></option>
                            <?php endforeach ?>
                        </select>
                    </td>
				</tr>
				<tr>
					<th><label for="player_name"><?php echo $grs->message('AddRecPlayerFormLabel') ?></label></th>
					<td>
                        <input type="text" name="player" />
                        <input type="button" class="button" onclick="checkPlayer()" value="Check" />
                    </td>
				</tr>
				<tr>
					<th><label><?php echo $grs->message('AddRecCarFormLabel') ?></label></th>
					<td>
                        <select id='cars_selection' name='car_id' disabled='true'></select>
                    </td>
				</tr>
				<tr>
					<th><label ><?php echo $grs->message('AddRecTimeFormLabel') ?></label></th>
					<td>
                        <input type="text" maxlength='2' size='2' name="time_hour" value="00"/>:
                        <input type="text" maxlength='2' size='2' name="time_minute" value="00"/>:
                        <input type="text" maxlength='2' size='2' name="time_second" value="00"/>    
                    </td>
				</tr>
			</table>
        </form>
    </div>